package com.cskaoyan.service;

import com.cskaoyan.bean.WXConfigBean;
import com.cskaoyan.bean.bo.ConfigMallBo;
import com.cskaoyan.bean.bo.ExpressConfigBo;
import com.cskaoyan.bean.bo.OrderConfigBo;
import com.cskaoyan.bean.po.ConfigMallPo;
import com.cskaoyan.bean.po.ExpressConfigPo;
import com.cskaoyan.bean.po.OrderConfigPo;
import com.cskaoyan.bean.vo.ConfigMallVo;
import com.cskaoyan.bean.vo.ExpressConfigVo;
import com.cskaoyan.bean.vo.OrderConfigVo;
import com.cskaoyan.mapper.ConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: DYQ
 * @time: Created on 2022/6/5 14:29
 */

@Service
public class ConfigServiceImpl implements ConfigService{

    @Autowired
    ConfigMapper configMapper;


    @Override
    public ConfigMallVo queryMallConfig() {
        ConfigMallPo configMallPo = configMapper.selectMallConfig();
        return ConfigMallVo.data(configMallPo.getMarketMallLongitude(),configMallPo.getMarketMallLatitude(),
                configMallPo.getMarketMallAddress(),configMallPo.getMarketMallQQ(),
                configMallPo.getMarketMallPhone(),configMallPo.getMarketMallName());
    }

    @Override
    public Void updateMallConfigInfo(ConfigMallBo configMallBo) {
        ConfigMallPo configMallPo = ConfigMallPo.data(configMallBo.getMarket_mall_longitude(), configMallBo.getMarket_mall_latitude(),
                configMallBo.getMarket_mall_address(), configMallBo.getMarket_mall_qq(),
                configMallBo.getMarket_mall_phone(), configMallBo.getMarket_mall_name());
        configMapper.updateMallConfigInfo(configMallPo);
        return null;
    }

    @Override
    public ExpressConfigVo queryExpress() {
        ExpressConfigPo expressConfigPo = configMapper.selectExpressConfig();
        ExpressConfigVo expressConfigVo = new ExpressConfigVo();
        expressConfigVo.setMarket_express_freight_min(expressConfigPo.getMarketExpressFreightMin());
        expressConfigVo.setMarket_express_freight_value(expressConfigPo.getMarketExpressFreightValue());
        return expressConfigVo;
    }

    @Override
    public void updateExpressConfig(ExpressConfigBo expressConfigBo) {
        ExpressConfigPo expressConfigPo = new ExpressConfigPo();
        expressConfigPo.setMarketExpressFreightMin(expressConfigBo.getMarket_express_freight_min());
        expressConfigPo.setMarketExpressFreightValue(expressConfigBo.getMarket_express_freight_value());
        configMapper.updateExpressConfig(expressConfigPo);
    }

    @Override
    public OrderConfigVo queryOrderConfig() {
        OrderConfigPo orderConfigPo = configMapper.selectOrderConfig();
        OrderConfigVo orderConfigVo = new OrderConfigVo();
        orderConfigVo.setMarket_order_comment(orderConfigPo.getMarketOrderComment());
        orderConfigVo.setMarket_order_unconfirm(orderConfigPo.getMarketOrderUnconfirm());
        orderConfigVo.setMarket_order_unpaid(orderConfigPo.getMarketOrderUnpaid());
        return orderConfigVo;
    }

    @Override
    public void updateOrderConfig(OrderConfigBo orderConfigBo) {
        OrderConfigPo orderConfigPo = new OrderConfigPo();
        orderConfigPo.setMarketOrderComment(orderConfigBo.getMarket_order_comment());
        orderConfigPo.setMarketOrderUnconfirm(orderConfigBo.getMarket_order_unconfirm());
        orderConfigPo.setMarketOrderUnpaid(orderConfigBo.getMarket_order_unpaid());
        configMapper.updateOrderConfigInfo(orderConfigPo);
    }

    @Override
    public WXConfigBean queryWXConfig() {
        WXConfigBean wxConfigBean = configMapper.selectWXConfig();
        return wxConfigBean;
    }

    @Override
    public void updateWXConfig(WXConfigBean wxConfigBean) {
        configMapper.updateWXConfigInfo(wxConfigBean);
    }
}
